package com.dut.bbs.web;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;

public class HttpClientFactory
{
    private static HttpClient client = null;
    private static final int REQUEST_TIMEOUT = 10 * 1000;// 设置请求超时10秒钟
    private static final int SO_TIMEOUT = 10 * 1000; // 设置等待数据超时时间10秒钟

    /**
     *
     * @return HttpClient对象
     */
    public static synchronized HttpClient getHttpClient()
    {
        if (client==null)
        {
            BasicHttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
            HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
            client = new DefaultHttpClient(httpParams);
        }
        return client;
    }
}
